package com.ls.pattern.behavior.mediator;

import java.util.HashMap;

public class ConcreteMediator extends Mediator {
    HashMap<String, Colleague> colleagueHashMap;
    HashMap<String, String> interMap;

    public ConcreteMediator() {
        colleagueHashMap = new HashMap<>();
        interMap = new HashMap<>();
    }

    @Override
    public void register(String name, Colleague colleague) {
        colleagueHashMap.put(name,colleague);
        if (colleague instanceof TV){
            interMap.put("TV",name);
        }else if (colleague instanceof CoffeeMachine){
            interMap.put("CoffeeMachine",name);
        }
    }

    //具体中介者的和兴方法
    @Override
    public void getMessage(int stateChange, String name) {
        if (colleagueHashMap.get(name) instanceof TV){
            TV tv = (TV)colleagueHashMap.get(name);
            if (stateChange == 0){
                tv.use();
            }else {
                tv.unUse();
            }
        }else if (colleagueHashMap.get(name) instanceof CoffeeMachine){
                CoffeeMachine coffeeMachine = (CoffeeMachine)colleagueHashMap.get(name);
            if (stateChange == 0){
                coffeeMachine.use();
            }else {
                coffeeMachine.unUse();
            }
        }
    }

    @Override
    public void sendMessage() {

    }
}
